<?php
namespace app\tree\model;
use app\base\model\BaseModel;
use think\Db;
use think\facade\Log;
/**
 * 
 */
class PlantModel extends BaseModel
{
	//种植树列表
	public function tree_list($data){
		if(empty($data['limit'])) $limit=10;
		if(empty($data['page'])||$data['page']<=0) $page=1;
		$limit = $data['limit'];
		$page = $data['page'];
		$pre = ($page-1)*$limit;
		// $res=Db::name('plant_tree')->alias('pt')->field('pt.treesid,pt.treesname,pt.energy,pt.treesimg,tp.name as prizeName,tp.imgPath as prizeImg')->join('prize tp','pt.prizeid = tp.prizeId')->where('pt.isuse',1)->order('pt.treesid','desc')->limit($pre,$limit)->select();
		$res=Db::name('plant_tree')->alias('pt')->field('pt.treesid,pt.treesname,pt.energy,pt.treesimg,tp.name as prizeName,tp.imgPath as prizeImg')->join('prize tp','pt.treesid = tp.treeId')->where('pt.isuse',1)->order('pt.treesid','desc')->limit($pre,$limit)->select();
		return $res;
	}

	//查找能量
	public function get_energy($data){
		$energy = DB::name('token_energy')->where('token',$data['Token'])->value('currentEnergy');
		return $energy;

	}
	//查找阶段

	public function get_tree_phase($treesid){
		$phase = DB::name('plant_trees_phase')->where('treesid',$treesid)->order('treesphase desc')->select();
		return $phase;
	}

	//查找家庭树 树的图片、树的背景
	public function find_tree($data){
		$res = Db::name('plant_trees_user')->alias('pt')->field('pt.totalenergy,pt.treeuserid,ptb.backgroudurl,ptp.Treesimg as treesimg ')->join('plant_trees_bd ptb','pt.treesphase = ptb.phase','left')->join('plant_trees_phase ptp','pt.treesphase = ptp.treesphase')->where('token',$data['Token'])->where('Iscomplete',0)->find();
		return $res;
	}

	//获得能量
	
	
	
	

}